<?php 
class Main_Paginator_Adapter_Db implements Zend_Paginator_Adapter_Interface
{
	/**
	 * @var Main_Db_Adapter_Abstract
	 */
	protected $_db;
	
	/**
	 * @var string
	 */
	protected $_sql;
	
	/**
	 * @var int
	 */
	protected $_count;
	
	/**
	 * @param Main_Db_Adapter_Abstract $db
	 * @param string $sql
	 * @param string $sqlCount
	 * @return void
	 */
	public function __construct(Main_Db_Adapter_Abstract $db, $sql, $sqlCount)
	{
		$this->_db = $db;
		$this->_sql = $sql;
		$this->_count = $this->_db->fetchOne($sqlCount);		
	}

	/**
	 * @return int
	 */
	public function count() 
	{
		return $this->_count;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see library/Zend/Paginator/Adapter/Zend_Paginator_Adapter_Interface#getItems()
	 */
	public function getItems($offset, $itemCountPerPage)
	{
		return $this->_db->fetchAllLimited($this->_sql, $itemCountPerPage, $offset);
	}	
	
}


